import {defineStore} from 'pinia';

export const useAuthStore = defineStore('auth', {
    state: () => ({
        isLoggedIn: false,
        visitorId: null, // 添加 visitorId 字段
        userName: null
    }), actions: {
        login(username) {
            this.isLoggedIn = true;
            this.userName = username;
        }, logout() {
            this.isLoggedIn = false;
            this.userName = null;
            this.visitorId = null;
        }, loginAsGuest(visitorId) {
            this.isLoggedIn = true;
            this.userName = "游客";
            this.visitorId = visitorId;
        },
    }, persist: {
        enabled: true, // 启用持久化
        strategies: [{
            storage: localStorage, // 使用 localStorage 存储
            // paths: ['isLoggedIn', 'visitorId', 'userName'],
        },],
    }
});